<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <body>

        <ui:composition template="./../template.xhtml">
            <ui:define name="meta">
                <c:if test="${user != null}">
                    <c:if test="${user.isAdmin == false}">
                        <meta http-equiv="refresh" content="0; URL=#{facesContext.externalContext.requestContextPath}/faces/403error.xhtml" />
                    </c:if>
                </c:if>
                <c:if test="${user == null}">
                    <meta http-equiv="refresh" content="0; URL=#{facesContext.externalContext.requestContextPath}/faces/login.xhtml" />
                </c:if>
            </ui:define>
            <ui:define name="title">
                Add Event Page
            </ui:define>

            <ui:define name="content">
                <h:form>
                    <p:panel header="Create New Event" style="text-align: center;width: 100%">
                        <center>
                            <h:panelGrid columns="2" style="width: 100%">
                                <h:outputLabel value="Event Name:*" for="txtEventName" />
                                <p:inputText maxlength="100" style="width: 30%;" id="txtEventName" value="#{eventController.selected.eventName}"
                                             title="" required="true"
                                             requiredMessage="Event name is required."
                                             validatorMessage="Event name field must between 4-50 characters">
                                    <f:validateLength minimum="4" maximum="50" for="txtEventName" />
                                </p:inputText><br/>
                                <p:row>
                                    <p:column colspan="2">
                                        <h:form enctype="multipart/form-data">
                                            <p:fileUpload fileUploadListener="#{eventController.insertAssignmentDetails}"
                                                          mode="advanced"
                                                          sizeLimit="1073741824"
                                                          allowTypes="/(\.|\/)(tif|jpg|png|gif)$/"
                                                          style="word-break:break-all;"/>
                                        </h:form>
                                    </p:column>
                                </p:row>
                                <h:outputLabel value="Event Title:*" for="txtEventTitle" />
                                <p:inputText maxlength="100" style="width: 30%;" id="txtEventTitle" value="#{eventController.selected.eventTitle}"
                                             required="true"
                                             requiredMessage="Event title is required."
                                             validatorMessage="Event title field must between 4-50 characters">
                                    <f:validateLength minimum="4" maximum="50" for="txtEventTitle" />
                                </p:inputText>


                                <h:outputLabel value="Description:*" for="txtDes" />
                                <p:inputTextarea maxlength="1000" rows="5" cols="30" id="txtDes" value="#{eventController.selected.descriptionEvent}"
                                                 validatorMessage="Description field must less than 1000 characters"
                                                 required="true"
                                                 requiredMessage="Event description is required.">
                                    <f:validateLength maximum="1000" for="txtEventTitle" />
                                </p:inputTextarea>


                                <h:outputLabel value="Max Player: *" for="txtMaxP" />
                                <p:inputText maxlength="2" style="width: 30%;" id="txtMaxP" value="#{eventController.selected.maxPlayer}"
                                             onkeypress="return numbersonly(event)"
                                             validatorMessage="Length of max player must between 1-99 characters"
                                             >
                                    <f:validateLength minimum="1" maximum="2"/>
                                </p:inputText>

                                <h:outputLabel value="Start Registration:*" for="dtpStartReg" />
                                <p:calendar navigator="true" effect="clip" id="dtpStartReg" pattern="dd-MMM-yyyy"
                                            mindate="#{eventController.today}"
                                            value="#{eventController.selected.startReg}" title="Start Registration"
                                            required="true" requiredMessage="Start Registration field is required.">
                                    <f:convertDateTime pattern="dd-MMM-yyyy" />
                                    <p:ajax event="dateSelect" update="dtpEndReg"></p:ajax>
                                </p:calendar>

                                <h:outputLabel value="End Registration:*" for="dtpEndReg" />
                                <p:calendar navigator="true" effect="clip" id="dtpEndReg"
                                            pattern="dd-MMM-yyyy" mindate="#{eventController.selected.startReg}"
                                            value="#{eventController.selected.endReg}" title="End Registration"
                                            required="true" requiredMessage="End Registration field is required.">
                                    <f:convertDateTime pattern="dd-MMM-yyyy" />
                                    <p:ajax event="dateSelect" update="dtpStartEvent"></p:ajax>
                                </p:calendar>

                                <h:outputLabel value="Start Event:*" for="dtpStartEvent" />
                                <p:calendar navigator="true"  id="dtpStartEvent" pattern="dd-MMM-yyyy" 
                                            mindate="#{eventController.selected.endReg}"
                                            value="#{eventController.selected.startEvent}" title="Start Event" effect="drop"
                                            required="true" requiredMessage="Start Event field is required.">
                                    <f:convertDateTime pattern="dd-MMM-yyyy" />
                                    <p:ajax event="dateSelect" update="dtpEndEvent"></p:ajax>
                                </p:calendar>

                                <h:outputLabel value="End Event:*" for="dtpEndEvent" />
                                <p:calendar navigator="true"  id="dtpEndEvent" pattern="dd-MMM-yyyy"
                                            mindate="#{eventController.selected.startEvent}"
                                            value="#{eventController.selected.finishEvent}" title="End Event" effect="drop"
                                            required="true" requiredMessage="End Event field is required.">
                                    <f:convertDateTime pattern="dd-MMM-yyyy" />
                                </p:calendar>





                            </h:panelGrid>
                            <h:outputText value="  " />
                            <p:commandButton id="btnCreate" action="#{eventController.create}" value="Create" ajax="false" icon="ui-icon-check" style="width: 120px;" />
                            <h:outputText value="  " />
                            <p:commandButton id="btnReset" type="reset" value="Reset" ajax="false" icon="ui-icon-close" style="width: 120px;" />
                            <h:outputText value=" " />
                            <p:commandButton id="btnCancel" action="#{eventController.cancelAddEvent}" value="Cancel" ajax="false"
                                             immediate="true" icon="ui-icon-arrowrefresh-1-w" style="width: 120px;"/>
                        </center>
                    </p:panel>
                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
